<template>
  <div class="app-container">
    <div class="app-title">
      <span>操作日志</span>
    </div>
    <div class="filter-container">

      <el-row>
        <el-col
          style="text-align: left; padding-left: 10px;"
          :span="4"
        >
          <!-- <i
            :class="[treeShow ? 'el-icon-s-fold treeI': 'el-icon-s-unfold treeI']"
            @click="toggerTree"
          /> -->

        </el-col>
        <el-col
          style="text-align: right;margin-top:-8px"
          :span="20"
        >
          <el-button
            size="small"
            class="filter-item"
            style="margin-left: 10px;"
            type="primary"
            @click="query"
          >
            查询
          </el-button>

        </el-col>
      </el-row>
    </div>
    <div
      ref="box"
      class="box"
    >
      <!-- <div
        class="left"
        :class="[isActive ? 'wid':'wids']"
      >
        <div :class="[treeShow ? 'treeShow' : 'treeNotShow']">
          <div style="height:40px; background-color:#ebecf1">
            <div style="width:100px;padding-top:10px;padding-left:20px">组织机构</div>
          </div>
          <el-input
            v-model="treeQuery"
            suffix-icon="el-icon-search"
            size="small"
            class="treeInput"
          />
          <el-tree
            ref="selectTree"
            :data="listTree"
            :props="defaultProps"
            :node-key="defaultProps.id"
            :filter-node-method="filterNode"
            @node-click="handleClick"
          />
        </div>
      </div> -->
      <!-- <div
        v-show="Show"
        class="resize"
        title="收缩侧边栏"
      /> -->
      <div
        class="mid"
        :class="[isActive ? 'mids': 'min']"
      >
        <div :class="[treeShow ? 'hasTree': 'notTree']">
          <el-table
            ref="singalTable"
            v-loading="listLoading"
            :data="list"
            :stripe="true"
            fit
            :height="tableHeight"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}"
          >
            <template slot="empty">
              <tableEmpty />
            </template>

            <el-table-column
              label="序号"
              type="index"
              align="center"
              width="50"
            />
            <el-table-column
              prop="createTime"
              label="时间"
              align="center"
            />
            <el-table-column
              prop="ueserName"
              label="操作人"
              align="center"
            />
            <el-table-column
              prop="userAgencyId"
              label="操作人单位"
              align="center"
            />
            <el-table-column
              prop="operateName"
              label="操作内容"
              align="center"
            />
            />
            <el-table-column
              prop="agencyId"
              label="相关单位"
              align="center"
            />
            <el-table-column
              prop="personId"
              label="相关人员"
              align="center"
            />
          </el-table>
          <el-dialog  v-dialogDrag  
            :close-on-click-modal="false"
            title="查询"
            :visible.sync="dialogQueryFormVisible"
            style="padding:0px;"
            width="50%"
          >
            <el-form
              ref="dataForm"
              class="dialog-Backgroundcolor"
              :model="listQuery"
              label-position="right"
              label-width="100px"
            >
              <el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="开始时间：">
                      <el-date-picker
                        v-model="listQuery.startDate"
                        type="date"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="结束时间：">
                      <el-date-picker
                        v-model="listQuery.endDate"
                        type="date"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期"
                      />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="操作人：">
                      <el-input
                        v-model="listQuery.ueserName"
                        class="inputWidth"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="操作内容：">
                      <el-input
                        v-model="listQuery.operateName"
                        class="inputWidth"
                      />
                    </el-form-item>
                  </el-col>

                </el-row>

                <el-button
                  type="primary"
                  style="float:right;"
                  @click="handleFilter"
                >
                  查询
                </el-button>

              </el-row>
            </el-form>
          </el-dialog>
          <!--分页 -->
          <pagination
            :total="total"
            :page.sync="listQuery.page"
            :limit.sync="listQuery.limit"
            @pagination="getList"
          />
        </div>
      </div>
    </div>
    <Drag ref="icon" />

  </div>

</template>

<script>
// 引入方法（增删改查）
import {
  getOperrateLogs
} from '@/api/operrateLogs/operrateLogs'
// 引入分页插件
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import Drag from '@/components/Drag'
import tableEmpty from '@/components/table/empty'

export default {
  name: 'UnitInformationMaintenance',
  // 分页组件
  components: { Pagination, Drag, tableEmpty },
  data() {
    return {
      tableHeight: null,
      dialogQueryFormVisible: false,
      treeQuery: '',
      isActive: true,
      Show: false,
      clearable: true,
      accordion: false,
      treeShow: false,
      saveLoading: false,
      that: this,
      list: null,
      listTree: null,
      listOptions: null,
      mineStatus: '',
      defaultExpandedKey: [],
      defaultProps: {
        id: 'id',
        children: 'children',
        label: 'label'
      },
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 200,
        title: undefined,
        type: undefined,
        agencyId: '0',
        endDate: null,
        startDate: null,
        ueserName: null,
        operateName: null

      }
    }
  },
  watch: {
    treeQuery(val) {
      this.$refs.selectTree.filter(val)
    },
    // 表格的数据数组
    list(val) {
      this.doLayout()
    }
  },
  mounted() {
    this.dragController()
    this.getTbHeight()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTbHeight)
  },
  created() {
    this.getList()
    // this.getTree()
  },
  methods: {
    // 获取table高度的方法
    getTbHeight() {
      this.tableHeight = window.innerHeight - 218
    },
    /* 重新渲染table组件 */
    doLayout() {
      this.$nextTick(() => {
        this.$refs.singalTable.doLayout()
      })
    },
    // 查询
    query() {
      this.dialogQueryFormVisible = true
    },
    // 拖拽
    dragController() {
      this.$refs.icon.dragControllerDiv()
    },
    // 获取所有数据
    getList() {
      this.listLoading = true
      getOperrateLogs(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      })
    },

    // 刷新
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
      this.dialogQueryFormVisible = false
      // this.getTree()
    },
    // 树查询过滤
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 切换树是否显示
    toggerTree() {
      this.isActive = !this.isActive
      this.Show = !this.Show
      this.treeShow = !this.treeShow
    },
    // 获取数内容
    // getTree() {
    //   getDepartmentTree(this.listQuery).then(response => {
    //     this.listTree = response.data
    //   })
    // },
    // 树点击
    handleNodeClick(data) {
      this.formData.parentId = data.id
      this.formData.parentName = data.label
      if (this.formData.parentName === '组织机构') {
        this.clearHandle()
      } else {
        this.$refs.selectReport.blur()
      }
    },
    handleClick(data) {
    //   this.listQuery.departmentId = data.id
    //   this.getList()
    },
    // 清除下拉树选中
    clearHandle() {
      this.formData.parentName = ''
      this.formData.parentId = null
      this.defaultExpandedKey = []
    }
  }
}
</script>
<style lang="scss" scoped>
@import "~@/styles/border.scss"; /*引入公共样式*/
.treeInput {
  width: 100% !important;
  height: 40px !important;

  .el-input__inner {
    height: 35px;
  }
}
</style>
